<?php
namespace gnomephp;
/**
 * Session storage engine, useful for storing and getting sessions.
 * Abstraction layer for session.
 * 
 * 
 * @author peec
 *
 */
class Session{
	
	
	public $vars = array();
	
	/**
	 * Constructs the session class
	 * Initializes vars.
	 */
	public function __construct(){
		if (isset($_SESSION) && count($_SESSION) > 0)$this->vars = $_SESSION;
	}
	
	/**
	 * Sets a session key to value.
	 * @param string $var Key of the session.
	 * @param mixed $value Value of the session.
	 */
	public function set($var, $value){
		$this->vars[$var] = $value;
	}
	
	/**
	 * Gets a session var, it returns NULL if it does not exist.
	 * @param string $var The key of the session.
	 */
	public function get($var){
		return isset($this->vars[$var]) ? $this->vars[$var] : null;
	}
	
	/**
	 * Deletes a specific session from the stack of sessions.
	 * @param string $var The key of the session.
	 */
	public function delete($var){
		if (isset($this->vars[$var]))unset($this->vars[$var]);
	}
	
	/**
	 * Gets an array of all the sessions stored.
	 */
	public function getSessions(){
		return $this->vars;
	}
	
	/**
	 * Assigns all the session variables to $_SESSION, making all the changes.
	 */
	public function save(){
		$_SESSION = $this->vars;
	}
	
	
	
}